<template>
  <div class="pushList">
    <el-row style="margin: 10px 0">
      <el-col :span="2">
        <el-button size="small" type="primary" @click="add">新增店铺</el-button>
      </el-col>
      <el-col :span="3">
          <el-input size="small" placeholder="按店铺名称查询" v-model="goodsNumber" class="input-with-select">
              <el-button @click="search('num')" slot="append" icon="el-icon-search"></el-button>
          </el-input>
      </el-col>
      <el-col :span="6">
          <el-select
              style="width:200px"
              size="small"
              filterable
              remote
              reserve-keyword
              placeholder="按商品状态查询"
          >
              <el-option
                  v-for="(item, index) in [{label: '已上架', value: 0},{label:'已下架', value:1},{label:'审核未通过',value:2}]"
                  size="small"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
              ></el-option>
          </el-select>
          <el-button size="small" type="primary">清空</el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-table :data="noticeData" style="width: 100%" border>
        <el-table-column type="index" label="序号"  align="center" :index="indexSort"></el-table-column>
        <el-table-column prop="storeId" label="店铺编号" align="center"></el-table-column>
        <el-table-column prop="storeName" label="店铺名称" align="center"></el-table-column>
        <el-table-column prop="categoryId" label="分类" align="center">
        </el-table-column>
        <el-table-column prop="status" label="状态" align="center">
            <template slot-scope="props">
                <span style="color: rgba(103,194,58)">{{props.row.status}}</span>
            </template>
        </el-table-column>
        <el-table-column prop="validityTime" label="有效期" align="center"></el-table-column>
        <el-table-column prop="businessHours" label="营业时间" align="center"></el-table-column>
        <el-table-column prop="price" label="起送价/元" align="center"></el-table-column>
        <el-table-column prop="linkman" label="联系人" align="center"></el-table-column>
        <el-table-column prop="address" label="地址" align="center"></el-table-column>
        <el-table-column prop="phone" label="联系电话" align="center"></el-table-column>
        <el-table-column prop="createDate" label="注册时间" align="center"></el-table-column>
        <el-table-column prop="picture" label="店铺头像" align="center">
          <template slot-scope="props">
            <img :src="props.row.picture" alt width="70"/>
          </template>
        </el-table-column>
        <el-table-column prop="businessLicence" label="营业执照" align="center">
          <template slot-scope="props">
            <img :src="props.row.businessLicence" alt width="70"/>
          </template>
        </el-table-column>
        <el-table-column prop="bgPicture" label="手持照片" align="center">
          <template slot-scope="props">
            <img :src="props.row.bgPicture" alt width="70"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="200">
          <template slot-scope="scope">
            <span
              class="el-tag el-tag--primary el-tag--small"
              style="cursor: pointer;"
              @click="pass(scope.row)"
              size="mini"
            >通过</span>
            <span
              class="el-tag el-tag--danger el-tag--small"
              style="cursor: pointer;"
              @click="noPass(scope.row)"
              size="mini"
            >未通过</span>
            <span
              class="el-tag el-tag--warning el-tag--small"
              style="cursor: pointer;"
              @click="modify(scope.row)"
              size="mini"
            >修改</span>
            <span
              class="el-tag el-tag--danger el-tag--small"
              style="cursor: pointer;"
              @click="reject(scope.row)"
              size="mini"
            >驳回</span>
            <span
              class="el-tag el-tag--danger el-tag--small"
              style="cursor: pointer;"
              @click="distribution(scope.row)"
              size="mini"
            >分配账号</span>
            <span
              class="el-tag el-tag--primary el-tag--small"
              style="cursor: pointer;"
              @click="operationRecord(scope.row)"
              size="mini"
            >操作记录</span>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row style="text-align: right;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[15, 50, 100, 200]"
        :page-size="pageSize"
        layout="->, sizes, prev, pager, next, jumper, total"
        :total="totalElements"
      ></el-pagination>
    </el-row>
    <addShop :off.sync="shopDialog" :rowData="rowdata" :title="title"></addShop>
  </div>
</template>

<script>
import { getShopList } from "@/api/supermarket/shop.js";
import * as util from "@/util/util.js";
export default {
  name: "store",
  components: {
    addShop: () => import("@/views/goodsSupermarket/store/addShop")
  },
  data() {
    return {
      noticeData: [],
      pageSize: 15,
      currentPage: 1,
      totalElements: 0,
      totalPages: 1,
      shopDialog: false,
      rowdata: {},
      title: "",
      modifyImg: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    add() {
      this.title = "新增店铺";
      this.shopDialog = true;
    },
    modify(row) {
      console.log("row", row);
      this.rowdata = row;
      this.title = "修改店铺";
      this.shopDialog = true;
    },
    pass(row) {},
    noPass(row) {},
    reject(row) {},
    distribution(row) {},
    operationRecord(row) {},
    del(row) {
      delActivity({
        id: row.carouselId
      }).then(
        res => {
          this.$notify.success("删除成功");
          this.getList();
        },
        err => {}
      );
    },
    getList() {
      getShopList({
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        type: 1
      }).then(
        res => {
          console.log("res店铺列表接口", res);
          this.noticeData = res.data.list;
          this.noticeData.forEach(e => {
            e.updateDate = util.timestampToTime(e.createTime);
            e.businessHours =
              util.timestampToTime(e.startTiem) +
              "至" +
              util.timestampToTime(e.endTime);
              e.status = e.status == 1 ? "审核通过" : "未知";
              e.categoryId = e.categoryId == 2 ? "百货类" : (e.categoryId == 1 ? "水果类" : "未知")
          });
          this.totalElements = res.data.total;
        },
        err => {}
      );
    },
    //序号
    indexSort(index) {
      if (this.currentPage > 1) {
        index = (this.currentPage - 1) * this.pageSize + index + 1;
      } else {
        index = index + 1;
      }
      return index;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
      console.log(`当前页: ${val}`);
    }
  }
};
</script>

<style lang="less" props>
.pushList {
}
</style>